/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.businessLayer;

import mnstudent.dataacesslayer.RegulationDAL;
import mnstudent.datatranferobject.RegulationDTO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author lee
 */
public class RegulationBLL {
   RegulationDAL regulationBLL;
    
    public RegulationBLL()
    {
        regulationBLL = new RegulationDAL();
    }
     /**
     * Ham lay tat ca cac khoa
     *
     * @return boolean
     */
    public ResultSet getAllRegulation() {
        
        return regulationBLL.getAllRegulation();
    }
    
     public ArrayList<RegulationDTO> getAllRegulationToArray() {
       
       ArrayList<RegulationDTO> temp = new ArrayList<>();
       ResultSet rs = regulationBLL.getAllRegulation();
       try {
           while(rs.next())
           {
               RegulationDTO objRegulation = new RegulationDTO(rs.getNString(1), rs.getNString(2), rs.getNString(3));
               temp.add(objRegulation);
           }
       } catch (SQLException ex) {
           ex.printStackTrace();
       }
       return temp;
    }
   
    /**
     * Ham lay khoa theo ma khoa
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getRegulationById(String _id)
    {
        return regulationBLL.getRegulationById(_id);
    }  
    
    public RegulationDTO getRegulationByIdToObject(String _id)
    {
        RegulationDTO regulation = null;
        ResultSet rs = getRegulationById(_id);
       try {
           while(rs.next())
           {
               regulation = new RegulationDTO(rs.getNString(1), rs.getNString(2), rs.getNString(3));
           }
       } catch (SQLException ex) {
           ex.printStackTrace();
       }
        return regulation;
    }
    /**
     * Ham lay khoa theo ma khoa
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getRegulationByLabel(String _label)
    {
        return regulationBLL.getRegulationByLabel(_label);
    }  
    public RegulationDTO getRegulationByLabelToObject(String _label)
    {
        RegulationDTO regulation = null;
        ResultSet rs = getRegulationByLabel(_label);
       try {
           while(rs.next())
           {
               regulation = new RegulationDTO(rs.getNString(1), rs.getNString(2), rs.getNString(3));
           }
       } catch (SQLException ex) {
           ex.printStackTrace();
       }
        return regulation;
    }
    /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _regulation
     * @return tue: thanh cong, false: that bai
     */
    public boolean updateRegulationByIdToDatabase(RegulationDTO _regulation)
    {
        return regulationBLL.updateRegulationByIdToDatabase(_regulation);
    }
    
     /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _regulation
     * @return tue: thanh cong, false: that bai
     */
    public boolean updateRegulationByLabelToDatabase(RegulationDTO _regulation)
    {
        return regulationBLL.updateRegulationByLabelToDatabase(_regulation);
    }
}
